package com.abaddon.model;

import java.util.ArrayList;
import java.util.List;

import com.google.android.maps.GeoPoint;

public class Place extends Tag {

	private List<String> categories = new ArrayList<String>();
	
	/**
	 * Set what categories are connected with a place
	 * @param categories Arraylist of categories
	 */
	public void setCategories(String[] categories){
		if(categories != null){
			this.categories.clear();
			for(int i = 0; i<categories.length; i++){
				addCategory(categories[i]);
			}
		}
	}
	
	/**
	 * Add a category to the list of categories
	 * @param category
	 */
	public void addCategory(String category){
		if(category != null && category.length()>0){
			categories.add(category);
		}
	}
	
	/**
	 * Creates a new place 
	 * @param geopoint GeoPoint with lat and long
	 * @param title Title of the place
	 * @param snippet Description of the place
	 * @param categories Categories of the place
	 */
	public Place(GeoPoint geopoint, String title, String snippet, String[] categories){
		super(geopoint, title, snippet);
		setCategories(categories);
	}
	
	/**
	 * Add several categories to the list of categories 
	 * @param categories
	 */
	public void addCategories(List<String> categories) {
		for(int i = 0; i<categories.size(); i++){
			addCategory(categories.get(i));
		}
	}
	
	/**
	 * Get all categories
	 * @return An array of all categories
	 */
	public String[] getCategoriesArray(){
		Object[] objCategories = categories.toArray();
		String[] categoriesArr = new String[objCategories.length];
		for (int i = 0; i<objCategories.length; i++){
			categoriesArr[i] = objCategories[i].toString();
		}
		return categoriesArr;
	}
	
	/**
	 * Get categories
	 * @return A list of all categories
	 */
	public List<String> getCategoriesList(){
		return categories;
	}
	
	@Override
	public String toString() {
		return ("Title: " + getTitle() + " Description: " + getSnippet() + " Point: " + getPoint().toString() );
	}
	
}
